/**
 * Copyright (c) 2010 Basil Shikin, BugStat Project
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.bugstat.common.reports;

/**
 * This class represents a tuple integer value. It is n-dimensional tuple (where n is defined
 * in constructor)
 *
 * @author Basil Shikin
 *
 */
public class TupleIntegerValue
    implements ReportValue
{
    private final Integer[] values;

    /**
     * Create new n-dimensional tuple.
     * 
     * @param n Dimensions of the tuple. Must be positive. 
     */
    public TupleIntegerValue( int n )
    {
        if ( n < 0 ) throw new IllegalArgumentException("Invalid dimentions specified: " + n );
        
        values = new Integer[ n ];
        for ( int i = 0; i < n; i++ ) values[i] = 0;
    }
    
    /**
     * Create new n-dimensional tuple.
     * 
     * @param values Values of the tuple. Must not be null. 
     */
    public TupleIntegerValue( Integer[] values )
    {
        if ( values == null ) throw new IllegalArgumentException("Invalid values specified");
        
        this.values = values;
    }
    
    /**
     * Get integer on i-th position of the tuple.
     * 
     * @param i Position of the tuple to get value at.
     * 
     * @return Value at i.
     */
    public Integer getValue( int i )
    {
        return values[i];
    }
    
    /**
     * Set integer on i-th position of the tuple.
     * 
     * @param i      Position of the tuple to get value at.
     * @param value  Value to set.
     */
    public void setValue( int i, Integer value )
    {
        values[i] = value;
    }

    
    /**
     * Get number of values in the tuple.
     * 
     * @return Tuple dimension.
     */
    public int getLength()
    {
        return values.length;
    }

    /**
     * Get maximum of the tuple
     * 
     * @return Maximum
     */
    public double getMaxValue()
    {
        int maxValue = Integer.MIN_VALUE;
        
        for ( Integer value : values )
        {
            if ( value != null )
            {
                if ( value > maxValue ) maxValue = value;
            }
        }
        
        return maxValue;
    }
}
